#include <cstdio>
#define lowbit(x) (x & (-x))

typedef long long ll;
const int N = 1e6 + 5, mod = 998244353;
int n, a[N], val[N];
ll fac;

inline void modify(int x) {
  while (x <= n) { val[x]++, x += lowbit(x); }
}

inline int query(int x) {
  int res = 0;
  while (x) { res += val[x], x -= lowbit(x); }
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("CantorExpansion.in", "r", stdin);
  freopen("CantorExpansion.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  int ans = 0;
  fac = 1;
  for (int i = n; i; --i) {
    ans += query(a[i]) * fac % mod;
    if (ans >= mod) ans -= mod;
    fac *= (n - i + 1);
    if (fac >= mod) fac %= mod;
    modify(a[i]);
  }
  printf("%d", ans + 1 >= mod ? ans + 1 - mod : ans + 1);
  return 0;
}